package com.atguigu.ai.chat.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Michael
 * @date: 2025/5/30
 * @desc:
 */
@RestController
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    // 实现简单的聊天功能
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg", defaultValue = "Who are you") String message) {
        return chatClient.prompt() // 提示词
                .user(message) // 用户输入信息
                .call() // 请求大模型
                .content(); // 获取大模型返回结果
    }
}
